package fightplan.algorithmen.ko;

import java.util.ArrayList;
import java.util.List;

import fightplan.business.Fight;
import fightplan.business.FightEntry;
import fightplan.business.FighterHolder;
import fightplan.business.Plan;

public class KOPlan extends Plan {
	private static final long serialVersionUID = 1L;

	private List<Fight> upperTrostRundeFights;
	private List<Fight> lowerTrostRundeFights;

	KOPlan(boolean trostrunde) {
		if (trostrunde) {
			upperTrostRundeFights = new ArrayList<Fight>();
			lowerTrostRundeFights = new ArrayList<Fight>();
		}
	}

	// special KO Plan features

	public Fight getRootFight() {
		return fights.get(0);
	}

	public List<Fight> getLowerTrostRundeFights() {
		return lowerTrostRundeFights;
	}

	public List<Fight> getUpperTrostRundeFights() {
		return upperTrostRundeFights;
	}

	public int calcDepth(Fight fight) {
		if (fight == null)
			return 0;
		int max = 0;
		for (FightEntry entry : fight.getFightEntries()) {
			if (entry.getFighterProvider() instanceof FighterHolder) {
				max = Math.max(max, calcDepth(((FighterHolder) entry.getFighterProvider()).getFight()));
			}
		}
		return max + 1;
	}

}